package com.castle.fortress.admin.message.sms.service.impl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.castle.fortress.admin.message.sms.service.SmsService;
import com.castle.fortress.common.entity.RespBody;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SpugSmsServiceImpl implements SmsService {
    private final String BASE_URL = "https://push.spug.cc/send/peJ9bm3wQYm6QDNy?code=#{smsCode}&number=3&targets=#{mobile}";
    private final String BASE_URL_EZ_MIND = "https://push.spug.cc/send/RNAXprQ9glrJQ0ew?code=#{smsCode}&targets=#{mobile}";

    @Override
    public RespBody send(String smsCode, String mobile, String params) {
        String url = BASE_URL_EZ_MIND.replace("#{smsCode}", smsCode).replace("#{mobile}", mobile);
        String res = HttpUtil.get(url);
        JSONObject jsonObj = JSONUtil.parseObj(res);

        log.info("短信url：{}", url);
        log.info("发送短信结果：{}", res);

        if (jsonObj.getInt("code") == 200) {
            return RespBody.data("发送成功");
        }

        return RespBody.fail(jsonObj.getStr("msg"));
    }
}
